# 建议使用 "import os" 风格而非 "from os import *"
# 这样可以保证随操作系统不同而有所变化的 os.open() 不会覆盖内置函数 open()
import os
import shutil
import glob
import sys
import math
from urllib.request import *
import smtplib
from datetime import *
import doctest

print(os.getcwd())  # 返回当前工作目录
os.chdir("D:/")  # 修改当前工作目录

# os.system("mkdir newFolderByPY")  # 执行命令 mkdir

# print(dir(os))  # <returns a list of all module functions>
# print(help(os))  # <returns an extensive manual page created from the module's docstrings>
shutil.copyfile("d2f42068.ini", "copiedFileByPY.txt")

os.chdir("D:\workspace\pycharm\python_primer")  # 修改当前工作目录

print(os.getcwd())  # 返回当前工作目录
print(glob.glob("*.py"))

print(sys.argv)

print("math.sin ", math.sin(math.pi/2))  # sin?
print("math.log", math.log(1024, 2))


# 网络
# lines = urlopen("http://www.prnasia.com")
# for line in lines:
#     print(line)
#     print(line.decode("UTF8"))

# smtp邮件
# 为什么可以完全隐藏收件人,或者伪造发件人和收件人???
# with smtplib.SMTP('119.254.10.218') as server:
#     server.sendmail('wen.gao@prnasia.com', 'wen.gao@prnasia.com',
#     """To: zhenli.liu@prnasia.com
# From: zhenli.liu@prnasia.com
# This is email content by python
#     """)
# server.quit()


# date
print(date.today().strftime("%Y-%m-%d %H:%M:%S"))
print(datetime.today().strftime("%Y-%m-%d %H:%M:%S"))
date1 = date(2008, 8, 8)
date2 = date(2008, 8, 10)
print(str(date2 - date1))
print((date2 - date1).days)


# doctest
def average(values):
    """Computes the arithmetic mean of a list of numbers.
    >>> print(average([20, 30, 70]))
    40.0
    """
    return sum(values) / len(values)


doctest.testmod()   # 自动验证嵌入测试
